{if $this->t_verify->is_post() && $this->t_verify->is_ajax()}
{if empty($list)}
<div class="alert alert-block">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <h4>Warning!</h4>
    暂时没有相关数据
</div>
{else}
{if $chart === '1'}
<table class="table table-hover table-striped">
    <thead>
        <tr>
            <th colspan="7" style="text-align:center">订单信息</th>
            <th colspan="5" style="text-align:center">产品信息</th>
        </tr>
        <tr><th style="width:20px"></th>
            <th>订单编号</th>
            <th>状态</th>
            <th>金额</th>
            <th>成本</th>
            <th>积分</th>
            <th>创建日期</th>
            <th>会员</th>
            <th>发货日期</th>
            <th>创建人</th>
            <th>产品数量</th>
            <th>购买金额</th>
            <th>购买积分</th>
            <th style="width:50px;text-align:center">查看</th>
        </tr>
    </thead>
    <tbody>
        {loop $list as $var}
    <script type="text/javascript">
        function product_data(id){
        $('.product_data').hide(); $('.product_dataplus').html('<i class=\'icon-plus\'></i>'); $('#product_data' + id).fadeIn(); $('#product_dataplus' + id).html('<i class=\'icon-minus\'></i>');
        }
    </script>
    <tr{$var.status==='-1'?' class="warning"':($var.status==='-2'?' class="error"':'')} onclick="product_data('{$var.id}')">
        <td class="product_dataplus" id="product_dataplus{$var.id}"><i class="icon-plus"></i></td>
        <td>{$var.number}</td>
        <td>{$this->m_orders->get_status($var.status)}</td>
        <td>{$var.amount}</td>
        <td>{$var.cost}</td>
        <td>{$var.points}</td>
        <td>{array_shift($this->t_date->get_lastdate((int) $var.time))}</td>
        <td>{$var.realname?:'<span class="label label-important">没有客户</span>'}</td>
        <td>{date('Y-m-d',$var.ship)}</td>
        <td>{$var.staff_realname}</td>
        <td>{$var.count_data}</td>
        <td>{$var.amount}</td>
        <td>{$var.points}</td>
        <td style="text-align:center"><a href="{site 'inventory/product_sales_look/'.$var.id}" title="查看记录"><i class="icon-search"></i> 查看</a></td>
    </tr>
    <tr id="product_data{$var.id}" class="product_data" style="display:none">
        <td colspan="13">
            <table class="table table-hover table-striped table-bordered" style="margin-bottom:0px">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>状态</th>
                        <th>数量</th>
                        <th>退货</th>
                        <th>购买金额</th>
                        <th>购买成本</th>
                        <th>购买积分</th>
                        <th>购买折扣</th>
                        <th>出库仓库</th>
                        <th>识别码</th>
                        <th>产品名称</th>
                        <th>产品单价</th>
                        <th>产品分类</th>
                        <th>产品类型</th>
                        <th>产品规格</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $this->m_orders_data->get_data($var.id) as $var2}
                    {_ $var2.product_data=unserialize($var2.product_data);}<tr>
                        <td>{sprintf("%06d",$var.id)}</td>
                        <td>{$this->m_orders_data->get_status($var2.status)}</td>
                        <td>{$var2.quantity}</td>
                        <td>{$var2.return}</td>
                        <td>{$var2.amount}</td>
                        <td>{$var2.cost}</td>
                        <td>{$var2.points}</td>
                        <td>{$var2.discounts}</td>
                        <td>{$var2.w_name}</td>
                        <td>{$var2.product_data.code}</td>
                        <td>{$var2.product_data.name}</td>
                        <td>{$var2.product_data.sales}</td>
                        <td>{$var2.product_data.category}</td>
                        <td>{$var2.product_data.type==='1'?'正常':'赠品'}</td>
                        <td>{$var2.product_data.format}</td>
                    </tr>
                    {/loop}
                </tbody>
            </table>
        </td>
    </tr>
    {/loop}

</tbody>
</table>
{else}

<table class="table table-hover table-striped table-bordered" style="margin-bottom:0px">
    <thead>
        <tr>
            <th>ID</th>
            <th>状态</th>
            <th>数量</th>
            <th>退货</th>
            <th>购买金额</th>
            <th>购买积分</th>
            <th>购买折扣</th>
            <th>出库仓库</th>
            <th>会员</th>
            <th>创建人</th>
            <th>创建时间</th>
             <th>发货日期</th>
            <th>识别码</th>
            <th>产品名称</th>
            <th>产品单价</th>
            <th>产品分类</th>
            <th>产品类型</th>
        </tr>
    </thead>
    <tbody>
        {loop $list as $var}
        {_ $var.product_data=unserialize($var.product_data);}<tr>
            <td>{sprintf("%06d",$var.id)}</td>
            <td>{$this->m_orders_data->get_status($var.status)}</td>
            <td>{$var.quantity}</td>
            <td>{$var.return}</td>
            <td>{$var.amount}</td>
            <td>{$var.points}</td>
            <td>{$var.discounts}</td>
            <td>{$var.w_name}</td>
            <td>{$var.realname?:'<span class="label label-important">没有客户</span>'}</td>
             <td>{$var.staff_realname}</td>
             <td>{array_shift($this->t_date->get_lastdate((int) $var.time))}</td>
             <td>{date('Y-m-d',$var.ship)}</td>
            <td>{$var.product_data.code}</td>
            <td>{$var.product_data.name}</td>
            <td>{$var.product_data.sales}</td>
            <td>{$var.product_data.category}</td>
            <td>{$var.product_data.type==='1'?'正常':'赠品'}</td>
        </tr>
        {/loop}
    </tbody>
</table>

{/if}
{/if}
{else}
{view 'public/head'}
</head>
<body>
    <div class="container-fluid">
        <form id="forminventorysupplier" class="form-inline" action="{site 'statistics/sales/'.$py}" accept-charset="utf-8" method="get">
            <table class="table table-hover">
                <tbody>

                    <tr>
                        <td>

                            <input type="text" placeholder="识别码/产品名称" name="keyword" value="{$_REQUEST.keyword}" class="input-medium">
                            <input size="16" type="text" class="form_datetime input-small" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" name="timea" value="{$_REQUEST.timea}" placeholder="创建开始日期">
                            <i class="icon-resize-horizontal"></i>
                            <input size="16" type="text" class="form_datetime input-small" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" name="timeb" value="{$_REQUEST.timeb}" placeholder="创建结束日期">

                            <div class="btn-group" data-toggle="buttons-radio">
                                <button type="button" onclick="$('#chartinput').val(0); $('form').submit()" class="btn{empty($chart)?' active':''}"><i class="icon-bar-chart"></i> 宏观图</button>
                                <button type="button" onclick="$('#chartinput').val(1); $('form').submit()" class="btn{$chart==='1'?' active':''}"><i class="icon-list-alt"></i> 订单列表</button>
                                <button type="button" onclick="$('#chartinput').val(2); $('form').submit()" class="btn{$chart==='2'?' active':''}"><i class="icon-table"></i> 产品列表</button>
                            </div>
                            <input type="hidden" id="chartinput" name="chart" value="{$chart}" />

                            <button type="submit" class="btn btn-primary input-small" title="查询银行"><i class="icon-search"></i> 搜索</button>
                            <button class="btn" type="button" onclick="$('.more_search').fadeToggle(); $('#financequerysearch').val($('#financequerysearch').val() == 1?0:1)"><i class="icon-rss"></i> 更多搜索</button>

                            

                            <input type="hidden" id="paginationinput" name="pagination" value="1" />
                            <input type="hidden" id="countinput" name="count" value="{$count}" />
                        </td>
                    </tr>
                    <tr class="more_search"{$_REQUEST.financequerysearch?'':' style="display:none"'}>
                        <td>

                            <input type="hidden" name="financequerysearch" id="financequerysearch" value="{$_REQUEST.financequerysearch?:0}" />
                            <input type="text" placeholder="订单号" name="number" value="{$_REQUEST.number}" class="input-medium">


                            <input type="text" placeholder="会员姓名" name="realname" value="{$_REQUEST.realname}" class="input-small">
                            <input type="text" placeholder="会员卡号" name="card" value="{$_REQUEST.card}" class="input-small">
                            <input type="text" name="id_card" value="{$_REQUEST.id_card}" placeholder="会员身份证号" class="input-small">
                            <input type="text" placeholder="会员电话" name="card" value="{$_REQUEST.tel}" class="input-small">
                            <input type="text" placeholder="会员QQ" name="qq" value="{$_REQUEST.qq}" class="input-small">

                        </td>

                    </tr>
                    <tr class="more_search"{$_REQUEST.financequerysearch?'':' style="display:none"'}>
                        <td>
                            <select name="warehouse" class="input-medium">
                                <option value="">所有仓库</option>
                                {loop $warehouse as $var}
                                <option value="{$var.w_id}"{$_REQUEST.warehouse===$var.w_id?' selected':''}>{$var.w_name}</option>
                                {/loop}
                            </select>
                            <select name="c_id" class="input-xlarge">
                                <option value="">所有分类</option>
                                {loop $category as $var}
                                <option value="{$var.id}"{$_REQUEST.c_id===$var.id?' selected':''}>{$var.name}</option>
                                {/loop}
                            </select>
                            <select name="type" class="input-small">
                                <option value="">类型</option>
                                <option value="1"{$_REQUEST.type==='1'?' selected':''}>正常</option>
                                <option value="2"{$_REQUEST.type==='2'?' selected':''}>赠品</option>
                            </select>
                            <select name="staff_uid" class="input-small">
                                <option value="">创建人</option>
                                {loop $this->m_staff->finds() as $staff}
                                <option value="{$staff.uid}"{$_REQUEST.staff_uid===$staff.uid?' selected':''}>{$staff.realname}</option>
                                {/loop}
                            </select>
                            <select name="status" class="input-small">
                                <option value="">状态</option>
                                <option value="1"{$_REQUEST.status==='1'?' selected':''}>已完成</option>
                                <option value="-1"{$_REQUEST.status==='-1'?' selected':''}>有退货</option>
                                <option value="-2"{$_REQUEST.status==='12'?' selected':''}>已退货</option>
                            </select>

                            <select name="mode" class="input-small">
                                <option value="0"{empty($_REQUEST.mode)?' selected':''}>金额</option>
                                <option value="1"{$_REQUEST.mode==='1'?' selected':''}>积分</option>
                            </select>

                        </td>

                    </tr>
                </tbody>
            </table>
        </form>

        
        {if empty($chart)}
<p>
            <small><i class="icon-info-sign"></i> 合计<strong>{array_sum($list.quantity)}</strong>个销售产品,合计销售额：<strong>{array_sum($list.sales)}</strong> 元,实际销售：<strong>{array_sum($list.actual)}</strong>元，销售利润：<strong>{array_sum($list.profit)}</strong> 元</small>
        </p>
        <div id="main" style="height:450px;border:0px solid #ccc;padding:10px;"></div>


        {else}
        <p>
            <small><i class="icon-info-sign"></i> 查询到了<strong>{$count}</strong>个销售记录,合计<strong>{array_sum($list.quantity)}</strong>个销售产品,合计销售额：<strong>{array_sum($list.sales)}</strong> 元 ，实际销售：<strong>{array_sum($list.actual)}</strong>元，销售利润：<strong>{array_sum($list.profit)}</strong> 元</small>
        </p>

        <div id="tablelist">

        </div>
        <div class="pagination pagination-centered">
            <ul id='pagination'>

            </ul>
        </div>
        {/if}

    </div>
    {view 'public/js'}
    {if empty($chart)}
    {js 'assets/echarts/esl/esl.js'}
    {js 'assets/echarts/echarts-plain.js'}
    <script type="text/javascript">
                var option = {
                title : {
                text:"销售统计观图",
                        subtext: '{$_REQUEST.timea}至{$_REQUEST.timeb}'
                },
                        tooltip : {
                        trigger: 'axis'
                        },
                        legend: {
                        data:['合计销售额', '实际销售', '销售利润']
                        },
                        toolbox: {
                        show : true,
                                feature : {
                                mark : {show: true},
                                        dataView : {show: true, readOnly: false},
                                        magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                                        restore : {show: true},
                                        saveAsImage : {show: true}
                                }
                        },
                        calculable : true,
                        xAxis : [
                        {
                        type : 'category',
                                boundaryGap : false,splitLine : {show : false},
                                data : [{implode(',', $list.date)}]
                        }
                        ],
                        yAxis : [
                        {
                        type : 'value'
                        }
                        ],
                        series : [
                        {
                        name:'合计销售额',
                                type:'bar',
                                smooth:true,
                                data:[{implode(',', $list.sales)}]
                        },
                        {
                        name:'实际销售',
                                type:'bar',
                                smooth:true,
                                data:[{implode(',', $list.actual)}]
                        },
                        {
                        name:'销售利润',
                                type: 'line',
                                smooth: true,
                                itemStyle: {normal: {areaStyle: {type: 'default'}}},
                                data:[{implode(',', $list.profit)}],
                                markLine : {
                                data : [
                                {type : 'average', name : '平均值'}
                                ]
                                }
                        }
                        ]
                };
                echarts.init(document.getElementById('main')).setOption(option);</script>
    {else}
    <script type="text/javascript">
                $(document).ready(function() {
        {if !empty($count)}
        $('#pagination').jqPaginator({
        totalCounts: {$count},
                pageSize:{$base.queqry},
                currentPage: 1,
                onPageChange: function(num, type) {
                $('#paginationinput').val(num);
                        $.post($('#forminventorysupplier').attr('action'), $('#forminventorysupplier').serialize(), function(data) {
                        $('#tablelist').html(data);
                        });
                }
        });
        {/if}

        });
    </script>
    {/if}
</body>
</html>
{/if}